// SPDX-License-Identifier: GPL-2.0

#ifndef _DEVICE_H_
#define _DEVICE_H_

#include <gmodule.h>
#include <stdint.h>
#include "gmodule.h"
#include "bus.h"
#include "device_driver.h"

struct device;
struct device_type {
	const char *name;
	const struct attribute_group **groups;
	char *(*devnode)(const struct device *dev, uint32_t *mode,
			 uint64_t *uid, uint64_t *gid);
	void (*release)(struct device *dev);

	const struct dev_pm_ops *pm;
};

struct device_attribute {
	ssize_t (*show)(struct device *dev, struct device_attribute *attr,
			char *buf);
	ssize_t (*store)(struct device *dev, struct device_attribute *attr,
			 const char *buf, size_t count);
};

struct dev_ext_attribute {
	struct device_attribute attr;
	void *var;
};

struct device_dma_parameters {
	unsigned int max_segment_size;
	unsigned int min_align_mask;
	unsigned long segment_boundary_mask;
};

enum device_link_state {
	DL_STATE_NONE = -1,
	DL_STATE_DORMANT = 0,
	DL_STATE_AVAILABLE,
	DL_STATE_CONSUMER_PROBE,
	DL_STATE_ACTIVE,
	DL_STATE_SUPPLIER_UNBIND,
};

enum dl_dev_state {
	DL_DEV_NO_DRIVER = 0,
	DL_DEV_PROBING,
	DL_DEV_DRIVER_BOUND,
	DL_DEV_UNBINDING,
};

enum device_removable {
	DEVICE_REMOVABLE_NOT_SUPPORTED = 0, 
	DEVICE_REMOVABLE_UNKNOWN,
	DEVICE_FIXED,
	DEVICE_REMOVABLE,
};
struct device {
	struct device		*parent;
	struct device_private	*p;

	const char		*init_name;
	const struct device_type *type;

	const struct bus_type	*bus;
	struct device_driver *driver;
	void		*platform_data;
	void		*driver_data;

	uint64_t		bus_dma_limit;
	const struct bus_dma_region *dma_range_map;

	struct device_node	*of_node;
	dev_t			devt;
	uint32_t			id;

	const struct class	*class;

	void	(*release)(struct device *dev);
	bool			offline_disabled:1;
	bool			offline:1;
	bool			of_node_reused:1;
	bool			state_synced:1;
	bool			can_match:1;
};

struct device_link {
	struct device *supplier;
	struct device *consumer;
	struct device link_dev;
	enum device_link_state status;
	uint32_t flags;
	bool supplier_preactivated;
};

#endif
